package org.rpc.provider;

import org.rpc.core.RpcProperties;
import org.rpc.registry.RegistryFactory;
import org.rpc.registry.RegistryService;
import org.rpc.core.RegistryType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 创建人 yinchuanbao
 * 创建时间 2021/11/16 16:38
 */
@Configuration

public class RpcProviderAutoConfiguration {

    @Resource
    private RpcProperties rpcProperties;

    @Bean
    RpcProvider init() throws Exception {
        RegistryType type = RegistryType.valueOf(rpcProperties.getRegistryType());
        RegistryService serviceRegistry = RegistryFactory.getInstance(rpcProperties.getRegistryAddr(), type);
        return new RpcProvider(rpcProperties.getServicePort(), serviceRegistry);
    }
}
